// pages/index/case_more.js
import { carBrand,caseMore } from '../../api/index'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:'',
    place: ['漆面膜','窗膜'],
    placeIndex:-1,
    brand:[],
    brandIndex:-1,
    caseArr:[],
  },
  bindPickerChangePlace: function(e) {
    this.setData({
      placeIndex: e.detail.value
    })
    this.caseMoreFn()
  },
  bindPickerChangeBrand: function(e) {
    this.setData({
      brandIndex: e.detail.value
    })
    this.caseMoreFn()
  },
  caseMoreFn(){
    const {  place,placeIndex,brand,brandIndex,type } = this.data
    const _place = place[placeIndex] ? place[placeIndex]: ''
    const _brand = brand[brandIndex] ? brand[brandIndex]: ''
    caseMore({place:_place,brand:_brand,type }).then(res=>{
      this.setData({ caseArr:res.data })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { type } = options
    let _type = ''
    if(type==='0'){
      _type='pic'
    }
    if(type==='1'){
      _type = 'mv'
    }
    this.setData({ type:_type })

    carBrand().then(res=>{
      let _data = res.data
      let _brand = []
      _data.map(item=>{
        _brand.push(item.name)
      })      
      this.setData({ brand:_brand })
    })

    this.caseMoreFn()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})